package com.zzq.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzq.dao.TravelItemMapper;
import com.zzq.entity.PageResult;
import com.zzq.entity.QueryPageBean;
import com.zzq.entity.Result;
import com.zzq.pojo.TravelItem;
import com.zzq.pojo.TravelItemExample;
import com.zzq.service.TravelItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 幼儿猿大班
 * 2021/7/21void
 */
@Service(interfaceClass=TravelItemService.class)
public class TravelItemServiceImpl implements TravelItemService {

    @Autowired
    private TravelItemMapper travelItemMapper ;
    @Override
    public void add(TravelItem travelItem) {
        travelItemMapper.insert(travelItem);
    }
    @Override
    public PageResult findPage(QueryPageBean queryPageBean){
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        TravelItemExample travelItemExample = new TravelItemExample();
        TravelItemExample.Criteria criteria = travelItemExample.createCriteria();
        if(queryPageBean.getQueryString()!=null && !"".equals(queryPageBean.getQueryString())){
            criteria.andCodeEqualTo(queryPageBean.getQueryString());
            travelItemExample.or().andNameLike("%"+queryPageBean.getQueryString()+"%");
        }
        List<TravelItem> travelItems = travelItemMapper.selectByExample(travelItemExample);
        PageInfo<TravelItem> itemPageInfo = new PageInfo<>(travelItems);
        return new PageResult(itemPageInfo.getTotal(),itemPageInfo.getList());

    }

    @Override
    public void delete(Integer id) {
        travelItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public TravelItem findById(Integer id) {
        TravelItem travelItem = travelItemMapper.selectByPrimaryKey(id);
        return travelItem;
    }

    @Override
    public void update(TravelItem travelItem) {
        travelItemMapper.updateByPrimaryKey(travelItem);
    }

    @Override
    public List<TravelItem> findAll() {
        List<TravelItem> travelItems = travelItemMapper.selectByExample(null);
        return travelItems;
    }


}
